﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ReadyApps.Data.Wiki;

namespace ReadyAppsTest.Data
{
    [TestClass]
    public class EditPermissionsTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Constructor Tests

        [TestMethod]
        public void EditPermissionsConstructorTest()
        {
            List<Tuple<PermissionSet, bool>> testCases = new List<Tuple<PermissionSet, bool>>();
            testCases.Add(new Tuple<PermissionSet, bool>(new PermissionSet(1), false));
            testCases.Add(new Tuple<PermissionSet, bool>(new PermissionSet(1), true));
            testCases.Add(new Tuple<PermissionSet, bool>(new PermissionSet(), false));
            testCases.Add(new Tuple<PermissionSet, bool>(new PermissionSet(), true));

            foreach (var testCase in testCases)
            {
                EditPermissions target = new EditPermissions(testCase.Item1, testCase.Item2);
                PrivateObject targetWrapper = new PrivateObject(target);
                Assert.AreEqual(testCase.Item1, (PermissionSet)targetWrapper.GetProperty("PermissionSet"));
                Assert.AreEqual(testCase.Item2, (bool)targetWrapper.GetProperty("PermissionsAreInherited"));
                Assert.AreEqual(!testCase.Item2, (bool)targetWrapper.GetProperty("ModifyOriginalPermissions"));
                PermissionsHierarchy hierarchy = (PermissionsHierarchy)targetWrapper.GetProperty("Hierarchy");
                Assert.IsNotNull(hierarchy);
                Assert.AreEqual(0, hierarchy.Count());
            }
        }

        #endregion
    }
}
